package Manage;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Info.BaogaoCI;
import Util.DatabaseConn;

public class BaogaoCM {
	private Connection conn;
	private ResultSet rs;
	private PreparedStatement pstmt;
	public List<BaogaoCI> findAll() {
		List<BaogaoCI> bcs = new ArrayList<BaogaoCI>();
		Connection conn = null;
		try {
			 conn = DatabaseConn.getConnection();
		     pstmt = conn.prepareStatement("select * from baogaoc");	     
		     rs = pstmt.executeQuery();
		     while(rs.next()){
				int id =  rs.getInt("id");
				String name = rs.getString("name");
				String age = rs.getString("age");
				String sex = rs.getString("sex");
				String card = rs.getString("card");
				String num = rs.getString("num");
				String type = rs.getString("type");
				String xueya = rs.getString("xueya");
				String xuechanggui = rs.getString("xuechanggui");
				String xiongtou = rs.getString("xiongtou");
				String xindiantu = rs.getString("xindiantu");
				String shili = rs.getString("shili");
				String tingli= rs.getString("tingli");
				String xiujue = rs.getString("xiujue");
				String yanhou = rs.getString("yanhou");
				String yijian = rs.getString("yijian");
				String time = rs.getString("time");
		     	BaogaoCI bc = new BaogaoCI(id, name, age, sex, card, num, type, xueya, xuechanggui, xiongtou, xindiantu, shili, tingli, xiujue, yanhou, yijian, time);
		     	bcs.add(bc);
			}
		} catch (Exception e) {

		} finally {
			DatabaseConn.closeConn(conn);
		}
		return bcs;
	}
	
	public BaogaoCI Find(String card) {
		new DatabaseConn();
		BaogaoCI bc = null;
		try {
			conn = DatabaseConn.getConnection();
			pstmt = conn.prepareStatement("select * from baogaoc where card=?");
			pstmt.setString(1, card);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				int id =  rs.getInt("id");
				String name = rs.getString("name");
				String age = rs.getString("age");
				String sex = rs.getString("sex");
				String num = rs.getString("num");
				String type = rs.getString("type");
				String xueya = rs.getString("xueya");
				String xuechanggui = rs.getString("xuechanggui");
				String xiongtou = rs.getString("xiongtou");
				String xindiantu = rs.getString("xindiantu");
				String shili = rs.getString("shili");
				String tingli= rs.getString("tingli");
				String xiujue = rs.getString("xiujue");
				String yanhou = rs.getString("yanhou");
				String yijian = rs.getString("yijian");
				String time = rs.getString("time");
		     	bc = new BaogaoCI(id, name, age, sex, card, num, type, xueya, xuechanggui, xiongtou, xindiantu, shili, tingli, xiujue, yanhou, yijian, time);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DatabaseConn.closeConn(conn);
		}
		return bc;
	}
}
